<template>
	<view class="page">
		<view class="product-card">
			<view class="img-box">
				<image class="img" src="/static/image/img_icon.png" mode="aspectFit"></image>
			</view>
			<view class="right-box">
				<view class="title">
					刚打电话尽
				</view>
				<view class="id">
					WL-214564564764231231
				</view>
				<view class="num">
					收货总数量：2.0
				</view>
			</view>
		</view>
		<view class="product-content">
			<view class="item">
				采购编号：1545635245256135232
			</view>
			<view class="item">
				<view class="title">
					请购数量：
				</view>
				<view class="value">
					22.0克
				</view>
			</view>
			<view class="item between">
				<view class="title">
					分配收货数
				</view>
				<input class="input" type="digit" @input="distributeCountChange($event,index,idex)" :value="it.distributeCount" />
				<view class="status">
					已签收
				</view>
				<view class="num">
					0.0
				</view>
			</view>
			<view class="item">
				<view class="title">
					选择工序
				</view>
				<view class="inputvalue" @click="goworkprocedure">
					原材料
				</view>
			</view>
			<view class="item">
				<view class="title">
					选择库位
				</view>
				<view class="inputvalue">
					SHQ-001
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		components:{
			
		},
		data() {
			return {
				
			}
		},
		methods: {
			/**
			 * 分配收货数改变数量触发事件
			 * @param {Object} e
			 * @param {Object} index
			 * @param {Object} idex
			 */
			distributeCountChange:function(e,index,idex){
				let info = this.info;
				this.$set(info[index].purchaseDistributeMaterials[idex],'distributeCount',e.detail.value);
				this.info = info;
			},
			/**
			 * 选择工序触发事件
			 */
			goworkprocedure: function(index,idex) {
				getApp().globalData.selected={index:index,idex:idex,info:{}};
				uni.navigateTo({
					url: '/order/workprocedure/index/index'
				});
			},
			confirm:function(){
				let that = this;
				// purchaseSignIn
				let signInfo = this.signInfo;
				let totalNum = 0;
				let distributeinfo = this.info;
				let storehouseInfo = this.storehouseInfo;
				let processesInfo = this.processesInfo;
				let data ={id:signInfo.signDetailDTO.id,purchaseId:signInfo.signDetailDTO.purchaseId,signMaterialReqs:[]};

				console.log('distributeinfo',distributeinfo);
					signInfo.signDetailDTO.materials.forEach(result=>{
						data.signMaterialReqs.push({actualReceiveCount:distributeinfo[0].signCount,id:result.id,materialId:result.materialId,materialNo:result.materialNo,processId:processesInfo.id,processNo:processesInfo.processNo,signMaterials:[],storehouseId:storehouseInfo.id,twoNumber:''});
						distributeinfo[0].purchaseDistributeMaterials.forEach(res=>{
							totalNum += parseFloat(res.distributeCount);
							data.signMaterialReqs[0].signMaterials.push({"number":res.distributeCount,"presentMaterialId":res.presentMaterialId,"processId":res.processesInfo.id,"processNo":res.processesInfo.processNo,"storehouseId":res.storehouseInfo.id});
						})
					})
					console.log(totalNum,distributeinfo[0].signCount);
					if(parseFloat(totalNum) > parseFloat(distributeinfo[0].signCount)){
						uni.showToast({
							title: '分配收货数量不能大于收货总货数',
							icon:'none',
							mask:true,
							duration: 2000,
						});
						return;
					}
				api.purchaseSignIn(data).then(res=>{
					uni.showToast({
						title: '提交成功',
						mask:true,
						duration: 2000,
						complete() {
							getApp().globalData.info = res.data;
							setTimeout(function(){
								uni.redirectTo({
									url:'/subcontractList/order/batch/index/index'
								});
							},2000)
						}
					});
				})
				// {"id":"1516704599092043777","purchaseId":"1516591158506467328","signMaterialReqs":[{"actualReceiveCount":"3.0","id":"1516704599364673537","materialId":"1506096646394916864","materialNo":"WL-202203221078815160","processId":"1390584953820942341","processNo":"0001","signMaterials":[{"number":"0.999","presentMaterialId":"1516589864262713344","processId":"1390584953820942341","processNo":"0001","storehouseId":"1462595594311827456"},{"number":"2.001","presentMaterialId":"1516590176326299648","processId":"1390584953820942341","processNo":"0001","storehouseId":"1462595594311827456"}],"storehouseId":"1462595594311827456","twoNumber":""}]}
			},
			/**
			 * 库位详情
			 */
			getStorehouses: function(id,index,idx) {
				api.getStorehouses({
					id: id
				},'only').then(res => {
					this.$set(this.info[index].purchaseDistributeMaterials[idx],'storehouseInfo',res.data);
				})
			},
			/**
			 * 签收物料触发事件
			 */
			getscanCode: function(index,idx) {
				let that = this;
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						let data = getUrlJson(res.result);
						console.log(getUrlJson(res.result));
						if (data.t == 'STOREHOUSE') {
							// 物料签收
							that.getStorehouses(data.id,index,idx);
						} else {
							uni.showToast({
								title: '暂不支持该类型二维码',
								icon: 'none',
								duration: 2000
							});
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		background-color: #fafafa;
		width: 100%;
		min-height: 100vh;
	}
	.product-card{
		margin:20rpx;
		border-radius: 10rpx;
		background-color: #465da3;
		padding:20rpx;
		display: flex;
		.img-box{
			width:150rpx;
			height: 150rpx;
			background-color: #eeeeee;
			.img{
				width: 60%;
				height: 60%;
				margin: 20%;
			}
		}
		.right-box{
			color: white;
			margin-left: 20rpx;
			.title{
				font-size:30rpx;
			}
			.id{
				margin-top: 10rpx;
				line-height: 60rpx;
				font-size: 28rpx;
			}
			.num{
				line-height:60rpx;
				font-size: 28rpx;
			}
		}
	}
	.product-content{
		background-color: #f2f2f2;
		width: calc(100% - 80rpx);
		margin: 0 40rpx;
		padding: 20rpx;
		box-sizing: border-box;
		.item{
			line-height: 60rpx;
			display: flex;
			padding:10rpx 0;
			font-size: 30rpx;
			.value{
				color:#1793c6;
			}
			.input{
				background-color:white;
				height: 60rpx;
				width:40%;
			}
			.status{
				color: white;
				font-size: 28rpx;
				line-height: 60rpx;
				background-color:#63c05a;
				border-radius:20rpx;
				padding: 0 10rpx;
			}
			.inputvalue{
				background-color: white;
				line-height: 60rpx;
				flex: 1;
				margin-left:20rpx;
				text-align: center;
			}
		}
		.between{
			justify-content: space-between;
		}
	}
</style>
